package com.wen.rabbitmq.work.fail;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * work工作队列公平分发
 */
public class Producer {

    public static void main(String[] args) {

        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("120.26.47.111");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("admin");
        connectionFactory.setPassword("admin");
        //虚拟访问节点
        connectionFactory.setVirtualHost("/");

        Connection connection = null;
        Channel channel = null;
        try{
            connection = connectionFactory.newConnection("生产者");
            channel = connection.createChannel();

            channel.queueDeclare("queue1",true,false,false,null);
            for (int i = 0; i < 20; i++) {
                String message = "分发消息"+i;
                channel.basicPublish("","queue1",null,message.getBytes());
            }
            System.err.println("消息发送成功");
        } catch (Exception e) {
            e.printStackTrace();
        }finally {

        }


    }

}
